package com.example.usercenter.sys.web;

import com.alibaba.fastjson.JSONObject;
import com.example.usercenter.common.base.ResponseData;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

import com.example.usercenter.common.base.BaseRestController;
import com.example.usercenter.common.base.BaseService;
import com.example.usercenter.sys.service.AuthorityService;
import com.example.usercenter.sys.entity.Authority;

@RestController
@RequestMapping(value="/authority")
public class AuthorityController extends BaseRestController<Authority, Long> {
    @Autowired
    private AuthorityService authorityService;

    protected BaseService<Authority, Long> getService(){
            return authorityService;
    }

    @Override
    @PreAuthorize("hasAuthority('AUTHORITY')")
    public ResponseData get(@PathVariable("id") Long id) {
        return super.get(id);
    }

    @Override
    @PreAuthorize("hasAuthority('AUTHORITY')")
    public ResponseData save(@RequestBody Authority entity) {
        return super.save(entity);
    }

    @Override
    @PreAuthorize("hasAuthority('AUTHORITY')")
    public ResponseData update(@RequestBody Authority entity) {
        return super.update(entity);
    }

    @Override
    @PreAuthorize("hasAuthority('AUTHORITY')")
    public ResponseData delete(@PathVariable("id") Long id) {
        return super.delete(id);
    }

    @Override
    @PreAuthorize("hasAuthority('AUTHORITY')")
    public ResponseData page(@RequestBody JSONObject params) {
        return super.page(params);
    }

    @Override
    @Secured({"ROLE", "AUTHORITY"})
    public ResponseData query(@RequestBody JSONObject params) {
        return super.query(params);
    }

    @PreAuthorize("hasAuthority('AUTHORITY')")
    @Override
    public ResponseData exists(@RequestBody JSONObject params) {
        return super.exists(params);
    }
}